#include <bits/stdc++.h>
using namespace std;

//!注意[1,4],[2,3]的情况

class Solution {
public:
    vector<vector<int>> merge(vector<vector<int>>& intervals) {
        sort(intervals.begin(), intervals.end());
        vector<vector<int>> ans;
        int n = intervals.size();
        for(int i=0; i<n-1; ++i){
            if(intervals[i][1]>=intervals[i+1][0] && intervals[i][1]<=intervals[i+1][1]){
                intervals[i+1][0] = intervals[i][0];
            }
            else if(intervals[i][1]>=intervals[i+1][0] && intervals[i][1]>intervals[i+1][1]){
                intervals[i+1][0] = intervals[i][0];
                intervals[i+1][1] = intervals[i][1];
            }
            else{
                ans.emplace_back(intervals[i]);
            }
        }
        ans.emplace_back(intervals[n-1]);
        return ans;
    }
};

int main(){

}